package com.sailfish.springbootdemo;

import com.sailfish.springbootdemo.service.db5.SfcScdpMSnDetailService;
import com.sailfish.springbootdemo.utils.CommonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.util.unit.DataSize;

import javax.servlet.MultipartConfigElement;
import java.util.regex.Pattern;

@Component
@EnableTransactionManagement
@SpringBootApplication
@EnableScheduling
@EnableAsync
//@MapperScan({"com.sailfish.springbootdemo.dao.db1", "com.sailfish.springbootdemo.dao"})
public class SpringbootdemoApplication implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootdemoApplication.class, args);
    }

    /**
     * 定时器【废弃】
     */
    /*public static void timer1(){
        Timer timer = new Timer();
        // 获取当前时间
        Calendar currentTime = Calendar.getInstance();
        // 设置任务执行时间为每天的三点
        Calendar scheduledTime = Calendar.getInstance();
        scheduledTime.set(Calendar.HOUR_OF_DAY, 1);
        scheduledTime.set(Calendar.MINUTE, 0);
        scheduledTime.set(Calendar.SECOND, 0);
        // 如果当前时间已经过了每天的三点，则将任务执行时间调整为第二天的三点
        if (scheduledTime.before(currentTime)) {
            scheduledTime.add(Calendar.DATE, 1);
            scheduledTime.add(Calendar.MINUTE, 0);

//            scheduledTime.add(Calendar.HOUR, 0);
//            scheduledTime.add(Calendar.MINUTE, 0);
//            scheduledTime.add(Calendar.SECOND, 20);
        }
        // 计算距离任务执行时间的时间间隔
        long delay = scheduledTime.getTimeInMillis() - currentTime.getTimeInMillis();
        System.out.println("start timer1=========" + delay);
        // 安排定时任务
        //自动刷新设备 保养状态的定时任务
        timer.schedule(new RefreshDeviceUpkeepTimer(), delay, 10000);
        //自动刷新 认证状态的定时任务
        timer.schedule(new RefreshValidityCertificationTimer(), delay, 24 * 60 * 60 * 1000);
    }*/

    /**
     * 文件上传配置
     *
     * @return
     */
    @Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        //文件最大
        factory.setMaxFileSize(DataSize.parse("1000MB")); //KB,MB
        /// 设置总上传数据总大小
        factory.setMaxRequestSize(DataSize.parse("1000MB"));
        return factory.createMultipartConfig();
    }

    @Autowired
    SfcScdpMSnDetailService sfcScdpMSnDetailService;

    @Override
    public void run(String... args) throws Exception {
//        sfcScdpMSnDetailService.scheduledCalculateFirstPassRate();
//        sfcScdpMSnDetailService.scheduledRefreshAxiData();
//        sfcScdpMSnDetailService.scheduledSendAxiMailToFactory();
//        sfcScdpMSnDetailService.scheduleRefreshAll0301CodeInfo();
//        sfcScdpMSnDetailService.scheduledSearchSfc();
//        sfcScdpMSnDetailService.scheduleFillPId();
//        sfcScdpMSnDetailService.scheduledSendAxiMailToApprover();
    }
}
